package yagwl.service.demo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@SuppressWarnings("serial")
@Entity
@Table(name = "CART")
public class CartEntity implements Serializable {

  private static final String entityCode = "CART";

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "CART_ID")
  private Long cartId;

  @Column(name = "USER_ID")
  private int userId;

  // TODO P2 change to Set
  @Column(name = "CART_LINE_IDS")
  private List<Long> cartLineIds = new ArrayList<Long>();

  @Transient
  private List<CartLineEntity> cartLines = new ArrayList<CartLineEntity>();

  void setCartId(Long cartId) {
    this.cartId = cartId;
  }

  Long getCartId() {
    return cartId;
  }

  //needed for multiple carts;  not needed for now
  //public String getId() {
  //  return encryptId(cartId);
  //}
  //
  //public void setId(String id) {
  //  cartId = decryptId(id);
  //}
  //
  //public static String encryptId(Long cartId) {
  //  return CryptoUtil.encryptLong(cartId, entityCode);
  //}
  //
  //public static Long decryptId(String encryptedId) {
  //  return CryptoUtil.decryptLong(encryptedId, entityCode);
  //}

  public void setUserId(int userId) {
    this.userId = userId;
  }

  public int getUserId() {
    return userId;
  }

  public void setCartLineIds(List<Long> cartLineIds) {
    this.cartLineIds = cartLineIds;
  }

  public List<Long> getCartLineIds() {
    return cartLineIds;
  }

  public void setCartLines(List<CartLineEntity> cartLines) {
    this.cartLines = cartLines;
  }

  public List<CartLineEntity> getCartLines() {
    return cartLines;
  }

}
